import React, { useState, useEffect, useReducer } from 'react'

function reducer(state,action){
    switch(action.type){
        case 'add':
            return state+action.num
        default:
            return state
    }
}

export default function Index() {
    const [count, dispatch] = useReducer(reducer,0)
    useEffect(() => {
        //引入了 count ===> let _count =count
        // 销毁 闭包保留引用的 _count
        setInterval(() => {
            dispatch({type:'add',num:1})
        }, 1000)
    }, [])
    return (
    <div>{count}</div>
  )
}
